﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form2 : Form
    {
        int Id1;
        string pd;
        public Form2()
        {
            InitializeComponent();
            pd = "添加";
        }
        public Form2(int Id, string Name, string Age,string Score)
        {
            InitializeComponent();
            textBox1.Text = Name;
            textBox2.Text = Age;
            textBox3.Text = Score;
            Id1 = Id;
            pd = "修改";
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.No;
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (pd.Equals("修改"))
            {
                var sql = string.Format("update Students set Name='{0}',Age='{1}',Score='{2}' where Id='{3}'", textBox1.Text, textBox2.Text,textBox3.Text, Id1);
                Dbsql.aud(sql);
                MessageBox.Show("修改成功", "提示");
            }
            else  if (pd.Equals("添加"))
            {
                var sql = string.Format("insert into Students (Name,Age,Score) values ('{0}','{1}','{2}')", textBox1.Text, textBox2.Text,textBox3.Text);
                Dbsql.aud(sql);
                MessageBox.Show("添加成功", "提示");
            }
            this.DialogResult = DialogResult.Yes;
            this.Hide();
        }
    }
}
